package fileparsing;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

import commonfunctions.Matrix;

import filewriting.PruneGraphWriter;

public class ReadPruned 
{
	/**
	 * Reads the pruned data from a file.
	 * 
	 * @param dirName
	 * @return
	 */
	public static Matrix prunedGraph(String dirName)
	{
		try
		{
			File f = new File(dirName + "/" + PruneGraphWriter.PRUNED_GRAPH_NAME);
			Scanner s = new Scanner(f);
			String firstRow = s.nextLine();
			String[] firstRowSplit = firstRow.split(" ");
			int size = Integer.parseInt(firstRowSplit[1]);
			Matrix toReturn = new Matrix(size);

			int rowNum = 0;

			for (int k = 0; k < size; k++)
			{
				for (int j = 0; j < size; j++)
				{
					toReturn.set(false, k,j);
				}
			}
			
			while(s.hasNext())
			{
				Scanner sLine = new Scanner(s.nextLine());
				if (sLine.hasNextInt())
				{
					//System.out.println(sLine.next());
					int colNum = sLine.nextInt();
					toReturn.set(true, rowNum, colNum);
				}
				rowNum++;
			}
			return toReturn;
		}
		catch(FileNotFoundException e)
		{
			System.out.println("Could not find file.");
			return new Matrix(0);
		}
	}
}
